//
//  EPMLoginViewController.m
//  myXianfeng
//
//  Created by 马继鵬 on 17/4/26.
//  Copyright © 2017年 EPM. All rights reserved.
//

#import "EPMLoginViewController.h"
#import <SMSSDK/SMS_SDK/SMSSDK.h>

@interface EPMLoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textPhoneNum;
@property (weak, nonatomic) IBOutlet UITextField *textCheckNum;
@property (weak, nonatomic) IBOutlet UIButton *logBtn;
@property (weak, nonatomic) IBOutlet UIButton *verifyBtn;

@end

@implementation EPMLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setupUI];
}
- (void)awakeFromNib{
    [super awakeFromNib];
    
}

#pragma mark - 设置初始化状态 -

- (void)setupUI{
    self.logBtn.enabled = NO;
    [self.logBtn.layer setMasksToBounds: YES];
    self.logBtn.layer.cornerRadius = 10;
   
    
}

- (IBAction)actionGetVerifyNum:(UIButton *)sender {
    if(self.textPhoneNum.text.length == 11){
        //#warning 发送消息
        [self verifybyNumber:self.textPhoneNum.text];
    }else{
        //加载MBP
        [self customViewExampleWithImage:@"loadFailed" title:@"手机号码填写不正确" View:self.view];
    }
}
- (IBAction)textEditChanged:(UITextField *)sender {
    
    if(self.textPhoneNum.text.length != 0 && self.textCheckNum.text.length != 0){
        self.logBtn.enabled = YES;
        self.logBtn.backgroundColor = appColor;
    }else{
        self.logBtn.enabled = NO;
        self.logBtn.backgroundColor = [UIColor lightGrayColor];
    }
    
    
}
- (IBAction)actionLogin:(id)sender {
    if (self.textCheckNum.text.length == 4){
        [ _LoginMgr loginWithPhone:self.textPhoneNum.text verify:self.textCheckNum.text finished:^(SMSSDKUserInfo *userInfo, NSError *error) {
            if(error == nil){
                [self customViewExampleWithImage:@"Checkmark" title:@"验证成功" View:self.view];
                [self.navigationController popToViewController:self.navigationController.viewControllers.firstObject animated:YES];
            }else{
                [self customViewExampleWithImage:@"loadFailed" title:@"验证失败" View:self.view];
                
            }
        }];
        
      }
}

- (void)verifybyNumber:(NSString *)phoneNum  {
    [_LoginMgr getVerifyWithPhoneNum:phoneNum reasult:^(NSError *error) {
        if(error == nil){
            [self customViewExampleWithImage:@"Checkmark" title:@"获取验证码成功" View:self.view];
        }else{
            [self customViewExampleWithImage:@"loadFailed" title:@"获取验证码失败" View:self.view];
        }
    }];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
